package com.flybook.web.controller.monitor;

import com.flybook.common.core.domain.R;
import com.flybook.system.domain.SysNotice;
import com.flybook.system.service.ISysNoticeService;
import com.flybook.utils.FlyBookUtils;
import com.flybook.web.controller.tool.FlyBookInfo;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/rest/plugin/service/flybooktalk")
public class FlyBookServiceRestController {

    @Autowired
    private ISysNoticeService sysNoticeService;

    @Autowired
    private FlyBookUtils flyBookUtils;

    @PostMapping({"/send"})
    @CrossOrigin
    @ResponseBody
    @ApiResponses({@ApiResponse(code = 0, message = "发送成功"), @ApiResponse(code = 500, message = "飞书发送错误信息")})
    public R sendTextMessage(@RequestBody FlyBookInfo flyBookInfo) throws Exception {
        SysNotice notice = sysNoticeService.selectNoticeById(flyBookInfo.getRobotKey());
        boolean res = flyBookUtils.SendToMsg(notice, flyBookInfo);
        return R.ok(res);
    }
}
